-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new clean, convert, export commands #30
Conversation
3604b46
to
326fa2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per our discussion, combine the export
and convert
commands.
a751747
to
f847b05
Compare
269f44b
to
093c1d9
Compare
093c1d9
to
5c5b4f5
Compare
Codecov Report
@@ Coverage Diff @@
## master #30 +/- ##
==========================================
+ Coverage 94.73% 98.31% +3.58%
==========================================
Files 2 8 +6
Lines 152 357 +205
==========================================
+ Hits 144 351 +207
+ Misses 8 6 -2
Continue to review full report at Codecov.
|
c89b83d
to
ed31b7b
Compare
ed31b7b
to
1412c15
Compare
13b128e
to
a44bae0
Compare
Okay, I think this should be ready to go.
|
Added new commands to the CLI. The summary of the commands are as follows:
clean
: Removes files that don't match whatnbautoexport
would create based on current notebooks and current config. For example, the use case is removing stuff likeUntitled.py
to clean up after stuff from renamed or deleted notebooks.convert
: This runs conversion with the configuration provided by CLI arguments (no .nbautoexport file needed).export
: This runs conversion on a folder with a .nbautoexport configuration file or with override CLI options.install
: The old main command of creating a .nbautoexport configuration file.Additional changes:
clean
configuration option to automatically run the cleaning as part ofpost_save
. Defaults toFalse
.rst
as an export format__main__.py
to support for calling withpython -m
. This requires settingtyper>=0.3.0
.Additional refactoring:
export.export_notebook
to better support code reuse forconvert
andexport
commands.os.path
to usepathlib
How stuff works:
clean
,, andconvert
export
know what files are notebooks:utils.find_notebook
will attempt to load every file in given directory withnbformat
.clean
knows what files to expect:clean.notebook_exports_generator
holds logic for predicting exported files.clean.get_extension
grabsnbconvert
exporters to figure out appropriate file extensionFixed some bugs:
asciidoc
,latex
,markdown
, andrst
formats create separate directories for image files that weren't getting moved into the subfolders.pdf
format resulted in a unicode decode error because the postprocessor was trying to read the pdf file back in as unicode text in order to remove the cell numbersnbconvert
grabs CLI arguments fromsys.argv
, which leads to really weird errors ifnbconvert
gets initiated through something likepytest
ornbautoexport
. Previously this was worked around in the tests by monkeypatchingsys.argv
. Instead, we now use a context manager to temporarily clearsys.argv
whenevernbconvert
is initialized, which prevents errors no matter if it wasnbautoexport
,pytest
, orjupyter
that starts the outer process.Looking for feedback:
Are the names of the commands clear?convert
andexport
could be confusing.Opened issue Split install command into install and configure #34install
is what the original function for setting up was named this whole time. Are there better names?configure
?watch
? I personally likewatch
.Right now we only supportOpened Proposal: Add support for having no subfolders #32organize_by
ofnotebooks
andextensions
. Wondering if it would make sense to supportNone
, i.e., keep converted output in parent directory and not in subfolders.TODO:
Known issues, thinking will save these for the future:
Determining appropriate file extension to get expected export files is currently clunky forended up implementingscript
.nbconvert
actually determines the language from loading the.ipynb
file and then dispatches to the specific language exporter. We may want to do the same thing.I don't actually know how to get the exporters for languages besides Python (expecting R and Julia?). TheRan this against an R notebook I had, and it looks up thenbconvert
library only directly supportspython
. We'll have to figure out how it knows about others. Currently this will return.txt
..r
from the notebook metadata underfile_extension
.The expected export files functionality does not support the subdirectories thatended up implementingasciidoc
,markdown
, andrst
create for images, soclean
will remove them. This may require figuring out naming conventions, and/or refactoring theexpected_exports
method to return globs instead of Paths.Functionality that searches for notebooks (ended up implementingclean
,export
,convert
) currently just glob for*.ipynb
files. This may miss stuff, and we should potentially instead try checking any file withnbformat
instead.Note: I tried to get the root of the CLI to point to
install
but it doesn't work, because other subcommands will conflict with arguments.Resolves #20, #21